<div class="admin">
    <div class="tab panel dux-tab admin-panel">
        <div class="panel-head"><strong>用户提问管理</strong></div>
        <div class="fixed-empty">
            <a href="{:U('addAdvice')}" class="button button-small border-green" style="margin-left: 20px;margin-top: 20px;">新增</a>
        </div>

        <form method="post" action="" name="formSearch" id="formSearch">
            <div class="table-tools clearfix ">
                <div class="float-left">
                    <div class="form-inline">
                        <div class="form-group">
                            <div class="field"><label>用户名：</label><input class="input input_small" type="text" name="user_name" value="" /></div>&nbsp;&nbsp;&nbsp;&nbsp;
                            <div class="field"><label>时间：</label>
                                <input class="input input_big hasDatepicker" type="text" value="" id="query_start_time" name="start_time" readonly="readonly">至
                                <input class="input input_big hasDatepicker" type="text" value="" id="query_end_time" name="end_time" readonly="readonly">
                            </div>
                            <input class="button bg-blue" type="submit" value="查询"/>
                        </div>
                    </div>
                </div>
            </div>
        </form>

        
        <form method="post" action="" name="myform" id="myform">
        <table class="table tb-type2 nobdb">
            <thead>
                <tr class="thead">
                    <th>序号</th>
                    <th>用户名</th>
                    <th>商品名</th>
                    <th class="align-center">提问</th>
                    <th class="align-center">解答</th>
                    <th class="align-center">是否显示</th>
                    <th class="align-center">提问时间</th>
                    <th class="align-center">用户</th>
                    <th class="align-center">操作</th>
                </tr>
            </thead>
            <tbody>
            <foreach item="v" name="list" key='k'>
                <tr class="hover">
                    <td>{$v['id']}</td>
                    <td>
                        <if condition="$v['user_id']">
                            <a href="{:U('User/details',array('user_id',$v['id']))}">{$v['user_name']}</a>
                            <else />
                            {$v['user_name']}
                        </if>
                    </td>
                    <td><a href="{:HOME_URL}/Goods/{$v['goods_id']}.html" target="_blank">{$v['goods_name']|sub_str=###,0,5}</a></td>
                    <td class="align-center">{$v['question']|sub_str=###,0,10}</td>
                    <td class="align-center">{$v['reply']|sub_str=###,0,10}</td>
                    <td class="nowrap align-center" onclick="is_show($(this),{$v['id']})">
                        {$v['is_show']?'<span style="color: #00aa00;font-weight:bold;cursor:pointer;"  is_show="1">√</span>':'<span style="color: red;font-weight:bold;cursor:pointer;"  is_show="0">×</span>'}
                    </td>
                    <td class="align-center">{$v['addtime']|date="y-m-d H:i:s",###}</td>
                    <td class="align-center">
                        <if condition="$v['user_id']">
                            是
                        </if>
                    </td>
                    <td class="w144 align-center">
                        <a class="button bg-green button-little" href="{:U('answer',array('id'=>$v['id']))}"><i class="icon-ellipsis-h"></i>解答</a>
                        <a class="button bg-red button-little" title="删除提问" onclick="del($(this),{$v['id']})"><i class="icon-minus-circle"></i>删除</a>
                    </td>
                </tr>
            </foreach>
            </tbody>
            <tfoot>
                <tr class="tfoot">
                    <td colspan="8"><div class="pages clearfix">{$page}</div></td>
                </tr>
            </tfoot>
        </table>
        </form>
    </div>
</div>
<script type="text/javascript">
    $('#query_start_time').duxTime({
        timepicker: false,
    });
    $('#query_end_time').duxTime({
        timepicker: false,
    });
</script>

<script type="text/javascript">
    //修改提问是否显示状态
    function is_show(t,id) {
        if(Number(t.find('span').attr('is_show'))){
            data = {is_show:0};
            txt = '隐藏该提问？';
        }else{
            data = {is_show:1};
            txt = '公开该提问？';
        }
        layer.confirm(txt, {
            btn: ['YES','NO'] //按钮
        }, function(){
            data.id = id;
            var p = Aajax('{:U('is_show')}',data);
            if(p.a){
                t.empty();
                if(data.is_show){
                    html = '<span style="color: #00aa00;font-weight:bold;cursor:pointer;"  is_show="1">√</span>';
                }else{
                    html = '<span style="color: red;font-weight:bold;cursor:pointer;"  is_show="0">×</span>';
                }
                t.html(html);
                layer.msg('修改成功');
            }else{
                layer.msg('失败请稍后重试');
            }
        })

    }

    //删除提问记录
    function del(t,id){
//        console.log(t);
        layer.confirm('删掉记录后将永久不在显示', {
            btn: ['确定删除','NO'] //按钮
        }, function(){
            data = {id:id};
            var p = Aajax('{:U('Advice/del')}',data);
            if(p.a){
                t.parents('tr').remove();
                layer.msg('已永久删除');
            }else{
                layer.msg('失败请稍后重试');
            }
        })
    }
</script>